# coding:utf8

from django.db import models

from django.contrib.auth.models import AbstractUser

# 将setting中的配置引入
from django.conf import settings


class Project(models.Model):
    """项目表"""
    name = models.CharField(max_length=100, verbose_name="项目", unique=True)
    describe = models.TextField(verbose_name="项目描述", null=True, blank=True)
    create_time = models.DateField(auto_now_add=True, verbose_name="创建时间")
    status = models.CharField(verbose_name="状态", choices=settings.STATUS_CHOICES, max_length=10, default='unfinished')

    class Meta:
        db_table = "ws_project"
        verbose_name = "项目"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name


class Job(models.Model):
    """任务表"""
    project_id = models.ForeignKey(Project, verbose_name="所属项目")
    name = models.CharField(max_length=100, verbose_name="任务")
    create_time = models.DateField(auto_now_add=True, verbose_name="创建时间")
    # update_time = models.DateField(auto_now=True, verbose_name="修改时间")
    status = models.CharField(verbose_name="状态", choices=settings.STATUS_CHOICES,max_length=10, default='unfinished')

    class Meta:
        db_table = "ws_job"
        verbose_name = "任务"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name


class Staff(AbstractUser):
    """账户表"""
    class Meta:
        db_table = "ws_staff"
        verbose_name = "账户"
        verbose_name_plural = verbose_name  # 不加这句，会在类名后面加个s，变成复数形式

    def __str__(self):
        return self.username


class Task(models.Model):
    """工作表"""
    project_id = models.ForeignKey(Project, verbose_name="项目")
    job_id = models.ForeignKey(Job, verbose_name="任务")
    staff_id = models.ManyToManyField(Staff, verbose_name="账户")
    content = models.TextField(max_length=1000, verbose_name="工作内容")
    duration = models.IntegerField(default=0, verbose_name="工作时长")
    start_time = models.CharField(verbose_name="开始时间", max_length=200, default='')
    end_time = models.CharField(verbose_name="结束时间", max_length=200, default='')
    # state = models.BooleanField(default=False, verbose_name="状态")
    # status = models.CharField(verbose_name="状态", choices=settings.STATUS_CHOICES,max_length=10, default="unfinished")

    class Meta:
        db_table = "ws_task"
        verbose_name = "工作"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.content



















